package cake.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cake.dao.UserDao;
import cake.service.UserService;

public class UserServlet extends HttpServlet {

	private UserService service;
	/**
	 * Constructor of the object.
	 */
	public UserServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		service=new UserService(request,response);
		
		
		response.setContentType("text/html");
		String action =request.getParameter("action");
		//��ȡajax����Ķ�������ݶ������зַ�����
		if(action.equals("login"))
		{
			//login
			service.login();
		}
		else if(action.equals("regist"))
		{
			//regist
			service.regist();
		}
		else if(action.equals("logout"))
		{
			//logout
			service.logout();
		}
		else if(action.equals("order"))
		{
			//order
			service.order();
		}
		else if(action.equals("cancel"))
		{
			//cancel order
			service.cancelOrder();
		}
		else if(action.equals("cancelDiy"))
		{
			//cancel order
			service.cancelDiyOrder();
		}
		else if(action.equals("updateOrder"))
		{
			//upate order
			service.updateOrder();
		}
		else if(action.equals("adminLogin"))
		{
			service.adminLogin();
		}
		else if(action.equals("adminLogout"))
		{
			service.adminLogout();
		}
		else if(action.equals("send"))
		{
			service.sendOrder();
		}
		else if(action.equals("sendDiy"))
		{
			service.sendDiyOrder();
		}
		else if(action.equals("confirm"))
		{
			service.confirmOrder();
		}
		else if(action.equals("confirmDiy"))
		{
			service.confirmDiyOrder();
		}
		else if(action.equals("adminCancel"))
		{
			service.cancelOrderByAdmin();
		}
		else if(action.equals("adminCancelDiy"))
		{
			service.cancelDiyOrderByAdmin();
		}
		else if(action.equals("addCart"))
		{
			service.addToCart();
		}
		else if(action.equals("addQ"))
		{
			service.addQ();
		}
		else if(action.equals("minusQ"))
		{
			service.minusQ();
		}
		else if(action.equals("deleteCart"))
		{
			service.deleteCart();
		}
		else if(action.equals("orderAll"))
		{
			service.orderAll();
		}
		else if(action.equals("clearCart"))
		{
			service.clearCart();
		}
		else if(action.equals("diy"))
		{
			service.diy();
		}
		else if(action.equals("leaveMsg"))
		{
			service.leaveMsg();
		}
		else if(action.equals("comment"))
		{
			service.comment();
		}
		else if(action.equals("deleteCake"))
		{
			service.deleteCake();
		}
		else if(action.equals("deleteComment"))
		{
			service.deleteComment();
		}
		else if(action.equals("editCake"))
		{
			service.editCake();
		}
		else if(action.equals("addCake"))
		{
			service.addCake();
		}
		else if(action.equals("updatePicture"))
		{
			service.updatePicture();
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
